package de.xt.logging.utils;

import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

/**
 * This class is a wrapper for the the properties class
 * 
 * @author XT-19
 * 
 */
public class Propertie {
	private String path;
	private Properties prob;

	/**
	 * Standard constructor for the class
	 * 
	 * @param pathToFile
	 *            String The path to the file
	 */
	public Propertie(String pathToFile) {
		this.path = pathToFile;
		this.prob = new Properties();

	}

	/**
	 * This function read the value of a given key
	 * 
	 * @param key
	 *            String The key
	 * @return String The Value for the Key
	 * @throws IOException
	 */
	public String readPropertie(String key) throws IOException {
		this.prob.load(new FileInputStream(this.path));
		return this.prob.getProperty(key);
	}

	/**
	 * Write a given value to a given key
	 * 
	 * @param key
	 *            String The key which should get the new value
	 * @param value
	 *            The value which should write to the file
	 * @throws IOException
	 */
	public void writePropertie(String key, String value) throws IOException {
		this.prob.store(new FileWriter(this.path), "Just an Update");
		this.prob.setProperty(key, value);

	}

	/**
	 * Returns the path to the properties file
	 * 
	 * @return String the path.
	 */
	public String getPath() {
		return this.path;
	}
}
